<?php
include('../include/config.php');
session_start();

$fullName = $_POST['fullName'];
$email = $_POST['email'];
$phoneNo = $_POST['phone'];
$regex_mail = '/^[_a-zA-Z0-9-]+(\.[_a-zA-Z0-9-]+)*@[a-zA-Z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$/';
$regex_phone = '/^[0-9]+$/';

if($email == '') {
    header('Location: user-account.php?error=5');
}
else if($fullName == '') {
    header('Location: user-account.php?error=6');
}
else if($phoneNo == '') {
    header('Location: user-account.php?error=7');
}
else if(!check_email($email)) {
    header('Location: user-account.php?error=8');
}
else if(!preg_match($regex_mail, $email)) {
    header('Location: user-account.php?error=9');
}
else if(!preg_match($regex_phone, $phoneNo)) {
    header('Location: user-account.php?error=10');
}
else {
    $userInfo = array();
    $userInfo['fullname']   = $fullName;
    $userInfo['email']      = $email;
    $userInfo['tel']        = $phoneNo;

    change_user_info($_SESSION["username"], $userInfo);
    echo "
    <script>
        alert('Success');
        window.location.href = 'user-account.php';
    </script>
    ";
}
?>